package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.DishDto;
import org.apache.ibatis.annotations.*;

import javax.xml.crypto.Data;
import java.util.List;

@Mapper
public interface DishMapper {


    @Select(" SELECT * FROM dish where category_id = #{id} ;")
    List<Dish> findDishByCategoryId( Long id );

    //添加菜品,然后id回显
    @Options(useGeneratedKeys = true , keyProperty = "id" )
    @Insert("INSERT INTO dish VALUES ( null , #{name} , #{categoryId} , #{price} , #{code} , #{image} ,  #{description} , #{status} , #{sort} , #{createTime} , #{updateTime} , #{createUser} , #{updateUser} , 0 );")
    void save(DishDto dishDto);

    //查看所有的Dish,通过名字
    List<Dish> findAll(String name);

    //根据id查看菜品
    @Select("select * from dish where id = #{id}")
    Dish findById(Long id);

    //更新菜品数据
    void update(DishDto dishDto);

    @Select("SELECT * FROM dish where category_id = #{categoryId} ;")
    List<Dish> findAllSaleByCategoryById(Long categoryId);

    //修改状态
    @Update("UPDATE dish SET status = #{status} , update_time = #{updateTime} , update_user = #{updateUser} WHERE id = #{id};")
    void status(Dish dish);

}
